package likou;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/17 08:29
 */
public class _17 {
    public static void main(String[] args) {
        System.out.println(letterCombinations("23"));
    }
    public static List<String> letterCombinations(String digits) {
        List<String> res = new ArrayList<>();
        char[] dcs = digits.toCharArray();
        String[] strs = new String[]{
                "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"
        };
        for(char now :dcs){
            int num = now-'0';
            if(num>9||num<2){
                continue;
            }
            String nowc = strs[num-2];
            int p = res.size();
            if(p>0){
                List<String> temp = new ArrayList<>(res);
                res = new ArrayList<>();
                for (char s : nowc.toCharArray()) {
                    for (String str : temp) {
                        res.add(str + s);
                    }
                }
            }else{
                for (char s : nowc.toCharArray()) {
                    res.add(String.valueOf(s));
                }
            }
        }
        return res;
    }
}
